package java.util.stream.dynamic_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author wangxiyue@cyou-inc.com
 * @date 2019-10-28
 * @since 1.0.0
 */
public class ProxyDemo {

    public static void main(String[] args) {
        ProxyClass proxyClass = new ProxyClass();

        ProxyInter proxy = (ProxyInter) Proxy.newProxyInstance(proxyClass.getClass().getClassLoader(),
                proxyClass.getClass().getInterfaces(), new InvocationHandler() {
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("代理方法..... before");
                        method.invoke(proxy, args);
                        System.out.println("代理方法..... after");
                        return null;
                    }
                });

        System.out.println(proxy.toString());

        proxy.test1();

    }

}
